<?php ob_start();
session_start(); //on relaye la session
if(isset($_SESSION["is_registered"]) && $_SESSION["is_registered"] == "registered"){
	$enregistrer = $_SESSION["is_registered"];
	$message="";
}else{
	header("Location:../../menu.php?erreur=intru"); // redirection en cas d'echec
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Recherche personne</title>
<link rel="stylesheet" type="text/css" href="../../css/main.css" />
<link rel="stylesheet" type="text/css" href="list.css" />
			<!--[if IE 7]>
            	<link rel="stylesheet" type="text/css" href="../../css/ie7.css" />
            	<link rel="stylesheet" type="text/css" href="form_ie7.css" />
            <![endif]-->



<script language="Javascript">
            <!--
                function modifier(choix){
                    var modifAct = document.getElementById("modifAct");
        			modifAct.href = 'saisiepersonne.php?val=rech&Identifiant_personne=' + choix;
        			
					//var suppAct = document.getElementById("suppAct");
        			//suppAct.href = 'saisierefexterne.php?Identifiant_personne=&Identifiant_refext=' + choix + '&supp=1' ;
                }
                
                function afficher(choix){
                    
                    var tesmed_err = document.getElementById("tesmed_err");
                    
                    //var ch = document.getElementById("choix");
        			
        			tesmed_err.href = 'recherchepersonne.php?Identifiant_personne=' + choix + '&valid=1';
                }
            //-->
            </script>
</head>



<?php 
	require_once('../../Connections/microassur.php'); 
	require_once('../../utils/fonctions.php');	
	$message = '';
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'%" . $theValue . "%'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];


$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
 $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

$where = "";

if ((isset($_POST["MM_rechercher"])) && ($_POST["MM_rechercher"] == "form1")) {
if($_POST['Type_personne']=="P")
{
	if(isset($_POST['Type_personne']) && !empty($_POST['Type_personne']))
		$where .= " AND Type_personne LIKE " . GetSQLValueString($_POST['Type_personne'], "text");
	if(isset($_POST['Nom_personne']) && !empty($_POST['Nom_personne']))
		$where .= " AND Nom_personne  LIKE " . GetSQLValueString($_POST['Nom_personne'], "text");
	if(isset($_POST['Prenom_personne']) && !empty($_POST['Prenom_personne']))
		$where .= " AND Prenom_personne LIKE " . GetSQLValueString($_POST['Prenom_personne'], "text");
	if(isset($_POST['Date_naissance_personne']) && !empty($_POST['Date_naissance_personne']))
		$where .= " AND Date_naissance_personne = " . GetSQLValueString(dateEN2FR($_POST['Date_naissance_personne']), "date");
		}
		else
		{
		
			if(isset($_POST['Type_personne']) && !empty($_POST['Type_personne']))
		$where .= " AND Type_personne LIKE " . GetSQLValueString($_POST['Type_personne'], "text");
	if(isset($_POST['Nom_personne']) && !empty($_POST['Nom_personne']))
		$where .= " AND  Raison_sociale  LIKE " . GetSQLValueString($_POST['Nom_personne'], "text");
	if(isset($_POST['Prenom_personne']) && !empty($_POST['Prenom_personne']))
		$where .= " AND Prenom_personne LIKE " . GetSQLValueString($_POST['Prenom_personne'], "text");
	if(isset($_POST['Date_naissance_personne']) && !empty($_POST['Date_naissance_personne']))
		$where .= " AND Date_naissance_personne = " . GetSQLValueString(dateEN2FR($_POST['Date_naissance_personne']), "date");
		
			
		}


$maxRows_rs1 = 10;
$pageNum_rs1 = 0;
if (isset($_GET['pageNum_rs1'])) {
  $pageNum_rs1 = $_GET['pageNum_rs1'];
}
$startRow_rs1 = $pageNum_rs1 * $maxRows_rs1;

mysql_select_db($database_microassur, $microassur);
	 $query_rs1 = "SELECT * FROM personne WHERE Etat_personne = 'A' " . $where ;
$query_limit_rs1 = sprintf("%s LIMIT %d, %d", $query_rs1, $startRow_rs1, $maxRows_rs1);
$rs1 = mysql_query($query_limit_rs1, $microassur) or die(mysql_error());
$num=mysql_num_rows($rs1);

$row_rs1 = mysql_fetch_assoc($rs1);
}
?>
<?php $url = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
  $url .= "?" . htmlentities($_SERVER['QUERY_STRING']."&recherche=0");
}


//MEDOUNE: verification si une personne existe dj pour le contrat en cours.
$test_s=0;
if(!isset($_POST['test']) && !isset($_GET['medtest'])){
	$sql="select * from role where Identifiant_contrat='".$_SESSION['idcontrat']."' and Type_role='".$_SESSION['role']."'";
	$requete_s=mysql_query("select * from role where Identifiant_contrat='".$_SESSION['idcontrat']."' and Type_role='".$_SESSION['role']."'") or die(mysql_error());
	$row_rl = mysql_fetch_assoc($requete_s);
	if($requete_s){
		$num_s=mysql_num_rows($requete_s);  
		if($num_s>=1){
			$test_s = 1;
		}	
	}
}
?>
<body>
<div id="sf_menu1">
<h3>Production </h3>
<?php
	

	if(isset($message) && !empty($message)){
		echo $message;
	}
	

	//if(isset($_GET['Identifiant_personne']) && $test_s==1){
//	if(isset($_SESSION['idcontrat']) && $test_s==1){
//		//echo aaa__.$test_s;
//		if($_SESSION['role']=="S")
//			echo colorer("Il ne peut y avoir qu'un seul souscripteur pour un contrat","false");
//			elseif($_SESSION['role']=="B")
//				echo colorer("Il ne peut y avoir qu'un seul bénéficiaire pour un contrat","false");
//	}
	
	$nommodule="Recherche personne";
	//$nommodule2="Liste des adresse";
	$nom_module_saisie="Souscription contrat";
	
	
?>
</div>
<div class="cleared"></div>
<div class="corps1">
<?php 
	require('../index.php');
	if(isset($message) && !empty($message)){
		echo $message;
	}
	
?>

<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">

 <div class="imgleft"></div>
	<div class="imgmiddle">
    <div class="btn">
    	<span class="btnleft"></span>
        <span class="btnmiddle">
        	<h5><?php echo $nom_module_saisie; ?></h5>
        </span><span class="btnright"></span>
    </div>
  	<div class="btn1">
    	<span class="btnleft"></span>
        <span class="btnmiddle">
        	<h5><?php echo $nommodule; ?></h5>
        </span>
        <span class="btnright"></span>
    </div>
    
	<div class="formulaire">
  <table class="tabform">
      <tr>
      <td  class="td0">TYPE </td>
      <td>
      
      <select name="Type_personne" id="Type_personne"  >
      <?php $requete=mysql_query("select elementdico.* from dictionnaire,elementdico where dictionnaire.Code_table='T0005' and dictionnaire.Identifiant_table=elementdico.Identifiant_table");
	 
	  while($reponse=mysql_fetch_array($requete)) {?>
        <option <?php  if(isset($_SESSION['Type_personne'])) echo remind_select1('Type_personne', $reponse["Code_element"]) ; else echo remind_select('Type_personne',$reponse["Code_element"]);?> value="<?php echo $reponse["Code_element"];?>"><?php echo $reponse["Nom_element"];?></option>
        <?php }?>
        </select>
      
          </td>
    </tr>
    <tr >
      <td class="td0">NOM </td>
      <td><input class="resize_2" type="text" name="Nom_personne" value="<?php echo remind_text('Nom_personne'); ?>" size="32" maxlength="30" /></td>
    </tr>
    <tr >
      <td class="td0">PRENOM</td>
      <td><input class="resize_2" type="text" name="Prenom_personne" value="<?php echo remind_text('Prenom_personne'); ?>" size="32" maxlength="30" /></td>
    </tr>
    <tr>
      <td class="td0">DATE NAISSANCE </td>
      <td><input class="date" type="text" name="Date_naissance_personne" value="<?php echo remind_text('Date_naissance_personne'); ?>" size="10" />&nbsp;</td>
    </tr> </table>
    
    </div> 
	<div class="bt1 bn"> <span class="btleft"></span>
	    <input type="submit" value="Rechercher" class="resizeall btmiddle"/>
        <span class="btright"></span></div>
	</div> 

<div class="imgright"></div>				
<div class="cleared"></div>

<h3>RESULTAT RECHERCHE </h3>
<div class="cleared"></div>
 <div class="imgleft"></div>
	<div class="imgmiddle">

<table class="tab_liste">
  <tr id="niv1">
   <td class="td0">&nbsp;</td>
    <td class="td1">NOM</td>
    <td class="td2">PRENOM</td>
    <td class="td4">DATE NAISSANCE</td>
    <td class="td5">LIEU NAISSANCE</td>
    <td>SEXE</td>
  </tr></table>
  <div class="content_table bright">
  <table class="tab_list">
  <?php $i=1; if(isset($num) && $num>0) {do {
  	if(isset($row_rs1['Type_personne']) && !empty($row_rs1['Type_personne'])){
  ?>
    <tr <?php if($i%2==0) echo 'class="colorligne"'; ?>>
    
    <td class="td0">
    <?php
  	
	if ((isset($_POST["MM_rechercher"]))) {
   //echo yes;
      	echo'<input onClick="modifier(this.value);" type="radio" id="choix" name="choix" value="'.$row_rs1['Identifiant_personne'].'" />';
	} else{
    	//echo $_POST["MM_rechercher"];
		echo'<input onClick="afficher(this.value);" type="radio" id="choix" name="choix" value="'.$row_rs1['Identifiant_personne'].'" />';  
	} 
    	?>
      	</td>
      
      <td class="td1"><?php if($row_rs1['Type_personne']=="P")echo $row_rs1['Nom_personne']; else echo $row_rs1['Raison_sociale']?></td>
      <td class="td2"><?php echo $row_rs1['Prenom_personne']; ?></td>
      <td class="td4"><?php echo dateEN2FR($row_rs1['Date_naissance_personne']); ?></td>
      <td class="td5"><?php echo $row_rs1['Lieu_naissance_personne']; ?></td>
      <td><?php  if($row_rs1['Sexe_personne']=='F') echo "F&eacute;minin" ; elseif($row_rs1['Sexe_personne']=='M') echo "Masculin" ; ?></td>
    </tr>
    <?php 
	$ty_pers=$row_rs1['Type_personne'];
	echo '<input type="hidden" name="Type_personne" value="'.$ty_pers.'" />';
	} $i++;
	} while ($row_rs1 = mysql_fetch_assoc($rs1)); mysql_free_result($rs1);
}  ?>
</table></div><div class="cleared"></div>
</div>

			<div class="imgright"></div>				
				<div class="cleared"></div>
				
					
					<?php
					if((isset($_GET["valid"])) && ($test_s==1))
						echo'<div class="bt1"><a href="index.php"><span class="btleft"></span><span class="btmiddle">Retour</span><span class="btright"></span></a></div>';
					else
						echo'<div class="bt1"><a href="'.$url.'"><span class="btleft"></span><span class="btmiddle">Retour</span><span class="btright"></span></a></div>';
					
			//modification pr permettre au boutin valider de s'afficher en modif	
//					if ((isset($_POST["MM_rechercher"]))  && ($test_s==1)) {
						
						echo '<div class="bt"><a id="modifAct" href="#"><span class="btleft"></span><span class="btmiddle">Valider</span><span class="btright"></span></a></div>';
//					}else{
//						echo $_POST["MM_rechercher"];
//						echo '<div class="bt"><a id="tesmed_err" href="#"><span class="btleft"></span><span class="btmiddle">Valider</span><span class="btright"></span></a></div>';
//						//echo '<div class="bt"><a href="recherchepersonne.php?Identifiant_personne="'.$row_rs1['Identifiant_personne'].'"><span class="btleft"></span><span class="btmiddle">Valider</span><span class="btright"></span></a></div>';
//					}
						?>
						
				<div class="cleared"></div>
		<input type="hidden" name="Identifiant_personne" value="" />
		<input type="hidden" name="MM_rechercher" value="form1" />
</form>
</div>
</body>
</html>
<?php
 ob_end_flush();?>